package com.lizemin.order.controller;

import cn.hutool.json.JSONUtil;
import com.lizemin.client.OrderClient;
import com.lizemin.common.ApiResponse;
import com.lizemin.req.CreateOrderReq;
import com.lizemin.resp.OrderResp;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;

/**
 * @author lzm
 * @date 2025/4/17 22:10
 * @description
 */
@Slf4j
@RestController
public class OrderController implements OrderClient {

    @Override
    public ApiResponse createOrder(@RequestBody CreateOrderReq createOrderReq) {
        log.info("接收到创建订单的请求, 请求参数为：{}", JSONUtil.toJsonStr(createOrderReq));
        return ApiResponse.success();
    }

    @Override
    public ApiResponse listOrders() {
        log.info("开始返回订单列表");
        ArrayList<OrderResp.Order> orders = new ArrayList<>();
        for (int i = 0; i < 3; i++) {
            OrderResp.Order order = new OrderResp.Order();
            order.setId(i + 1);
            order.setProductId(i + 1000);
            orders.add(order);
        }
        return ApiResponse.success(new OrderResp(orders));
    }

}
